package com.medical.view.wicket.ajax.html;

import org.apache.wicket.Component;
import org.apache.wicket.behavior.AbstractBehavior;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.form.FormComponent;

public class ValidationStyleBehavior extends AbstractBehavior {

	   //Check if the component is valid and add the corresponding CSS style attribute
	  public void onComponentTag(final Component component,
	      final ComponentTag tag) {

	   //Wicket has a Component hierarchy similar to Swing and TextField "is a" FormComponent.
	   //We 'downcast' in this case as we need to access certain methods defined at the FormComponent level.

	      FormComponent comp = (FormComponent) component;
	      if (comp.isValid() && comp.getConvertedInput() != null) {
//	         tag.getAttributes().put("class", "valid");
//	      } else if (!comp.isValid()) {
	         tag.getAttributes().put("class", "invalid");
	      }
	  }
	}